<template>
   <span>
    <el-drawer title="快速筛选" :visible.sync="dialogFormVisible" width="15%"  custom-class="demo-drawer">
      <el-form :model="filterForm" label-width="100px" custom-class="demo-drawer__content">
        <el-form-item label="用例集名称">
          <div style="width: 350px;">
            <el-input v-model="filterForm.suite_name" autocomplete="off"></el-input>
          </div>
        </el-form-item>
        <el-form-item label="创建人">
          <el-select v-model="filterForm.creator" placeholder="请选择创建人">
            <el-option
              v-for="item in creators"
              :key="item.staffNamePY"
              :value="item.staffNamePY"
              :label="item.staffNameCN">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="关联需求">
          <div style="width: 350px">
            <el-input v-model="filterForm.story" autocomplete="off"></el-input>
          </div>
        </el-form-item>
        <el-form-item label="用例关键词">
          <div style="width: 350px">
            <el-input v-model="filterForm.keywd" autocomplete="off"></el-input>
          </div>
        </el-form-item>
        <el-form-item label="时间">
          <el-date-picker
            v-model="filterForm.fdate"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="handleDate">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div class="demo-drawer__footer">
        <span>
          <el-button @click="resetBtn">重 置</el-button>
        </span>
        <span  style="position: relative;left: 30px;">
          <el-button type="primary" @click="searchBtn">搜 索</el-button>
        </span>
      </div>
    </el-drawer>
   </span>
</template>

<script>
export default {
  name: "CaseFilter",
  props: {
    creators: {
      type: Array,
      defaults: () => []
    }
  },
  data() {
    return {
      dialogFormVisible: false,
      filterForm: {
        suite_name: '',
        creator: '',
        fdate: [],
        story: '',
        keywd: '',
      },
    }
  },
  methods: {
    showDialog: function () {
      this.dialogFormVisible = true
      this.filterForm.suite_name = ''
      this.filterForm.creator = ''
      this.filterForm.story = ''
      this.filterForm.keywd = ''
      this.filterForm.fdate = []
    },
    handleDate: function (value) {
      this.filterForm.fdate = value.map((item) => {
        let temp_date = new Date(item)
        return temp_date.getFullYear() + '-' + (temp_date.getMonth() + 1) + '-' + temp_date.getDate()
      })
    },
    resetBtn() {
      this.filterForm.suite_name = ''
      this.filterForm.creator = ''
      this.filterForm.story = ''
      this.filterForm.keywd = ''
      this.filterForm.fdate = []
      this.doFilter()
    },
    searchBtn() {
      this.dialogFormVisible = true
      this.doFilter()
    },
    doFilter() {
      let filterParams = {
        "nameFilter" : this.filterForm.suite_name,
        "createrFilter": this.filterForm.creator,
        "storyFilter": this.filterForm.story,
        "caseKeyWords": this.filterForm.keywd,
        "choiseDate": this.filterForm.fdate
      }
      this.$emit('filterCondition', filterParams)
    }
  }
}
</script>

<style lang="less">
.demo-drawer {
  .el-drawer__header {
    span {
      font-size: 20px;
    }
  }
}
</style>
